package net.wanho.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.wanho.constant.CommonConstant;
import net.wanho.mapper.InStoreMapper;
import net.wanho.po.BuyList;
import net.wanho.po.InStore;
import net.wanho.service.BuyListService;
import net.wanho.mapper.BuyListMapper;
import net.wanho.service.InStoreService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
* @author Administrator
* @description 针对表【buy_list(采购单表)】的数据库操作Service实现
* @createDate 2024-10-18 16:14:23
*/
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class BuyListServiceImpl extends ServiceImpl<BuyListMapper, BuyList>
    implements BuyListService{

    private final InStoreMapper inStoreMapper;

    @Override
    public void inWarehouseRecordAdd(BuyList buyList) {
        /**
         * 修改采购单状态
         */
        buyList.setIsIn(CommonConstant.IS_IN);
        this.updateById(buyList);

        /**
         * 新增入库单
         */
        InStore inStore = new InStore();
        BeanUtils.copyProperties(buyList,inStore);
        inStore.setInNum(buyList.getFactBuyNum());
        inStore.setIsIn(CommonConstant.NOT_IN);
        inStoreMapper.insert(inStore);
    }
}




